package cn.csc.module.product.api.spu;

import cn.csc.framework.common.pojo.CommonResult;
import cn.csc.module.product.api.spu.dto.SpuDTO;
import cn.csc.module.product.convert.spu.SpuConvert;
import cn.csc.module.product.service.spu.SpuService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigInteger;
import java.util.List;
import java.util.Map;

import static cn.csc.framework.common.pojo.CommonResult.success;
import static cn.csc.module.product.enums.ApiConstants.VERSION;

/**
 * spu api
 * @author liuchuang
 * @version 1.0
 * @date 2024/1/25 14:55
 * @modify
 */
@RestController // 提供 RESTful API 接口，给 Feign 调用
@DubboService(version = VERSION) // 提供 Dubbo RPC 接口，给 Dubbo Consumer 调用
@Validated
public class SpuApiImpl implements SpuApi {

    @Autowired
    private SpuService spuService;


    @Override
    public CommonResult<SpuDTO> getSpu(BigInteger id) {

        return success(SpuConvert.INSTANCE.convertDTO(spuService.getSpu(id)));
    }

    @Override
    public CommonResult<Long> getSkuCount(BigInteger shopId) {
        return success(spuService.selectOKSpuNum(shopId));
    }

    /**
     * 通过店铺ID列表获取店铺的商家商品数
     *
     * @param shopIds 店铺ID列表
     * @return
     */
    @Override
    public CommonResult<Map<String, Object>> getSkuCountByShopIds(List<BigInteger> shopIds) {
        return success(spuService.getSkuCountByShopIds(shopIds));
    }

    @Override
    public CommonResult<List<SpuDTO>> getSpuList(List<BigInteger> ids) {
        return  success(SpuConvert.INSTANCE.convertList03(spuService.getSpuList(ids)));
    }

}
